import Toast from 'tdesign-miniprogram/toast/index'
// import i18nInstance from '../../miniprogram_npm/miniprogram-i18n-plus/index '
import { config } from "../../config/index"
Page({
  data: {
    goodsList: []
    //#region 
    // {
    //   goods_id: 111,
    //   goods_name: '创维（Skyworth）65V9E 65英寸25核4K HDR高清智能电视',
    //   goods_price: 6499,
    //   goods_Type: '待确认',
    //   goods_small_logo: 'http://image2.suning.cn/uimg/b2c/newcatentries/0070078057-000000000634917020_1_400x400.jpg',
    // },
    // {
    //   goods_id: 222,
    //   goods_name: '创维（Skyworth）65V9E 65英寸25核4K HDR高清智能电视',
    //   goods_price: 6499,
    //   goods_Type: '预定',
    //   goods_small_logo: 'http://image2.suning.cn/uimg/b2c/newcatentries/0070078057-000000000634917020_1_400x400.jpg',
    // },
    // {
    //   goods_id: 333,
    //   goods_name: '创维（Skyworth）65V9E 65英寸25核4K HDR高清智能电视',
    //   goods_price: 6499,
    //   goods_Type: '已取消',
    //   goods_small_logo: 'http://image2.suning.cn/uimg/b2c/newcatentries/0070078057-000000000634917020_1_400x400.jpg',
    // },
    // {
    //   goods_id: 444,
    //   goods_name: '创维（Skyworth）65V9E 65英寸25核4K HDR高清智能电视',
    //   goods_price: 6499,
    //   goods_Type: '待确认',
    //   goods_small_logo: 'http://image2.suning.cn/uimg/b2c/newcatentries/0070078057-000000000634917020_1_400x400.jpg',
    // },
    // {
    //   goods_id: 555,
    //   goods_name: '创维（Skyworth）65V9E 65英寸25核4K HDR高清智能电视',
    //   goods_price: 6499,
    //   goods_Type: '待确认',
    //   goods_small_logo: 'http://image2.suning.cn/uimg/b2c/newcatentries/0070078057-000000000634917020_1_400x400.jpg',
    // },
    // {
    //   goods_id: 666,
    //   goods_name: '创维（Skyworth）65V9E 65英寸25核4K HDR高清智能电视',
    //   goods_price: 6499,
    //   goods_Type: '待确认',
    //   goods_small_logo: 'http://image2.suning.cn/uimg/b2c/newcatentries/0070078057-000000000634917020_1_400x400.jpg',
    // }
    //#endregion
  },
  onLoad() {
    this.init()
  },
  onShow() {
    var that = this
    wx.request({
      url: `http://192.168.2.43:3000/QueryUserShoppingCard`,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        'userid': 1
      },
      success(res) {
        // 请求成功时的回调函数 
        if (res.data.code == 200) {
          that.setData({
            goodsList: res.data.data
          })
        } else {
          console.log(res.data.msg)
        }
      },
      fail(err) {
        // 请求失败时的回调函数  
        console.error(err)
        // 处理请求失败的情况，如显示错误提示  
      }
    })
    this.init()
  },
  onPullDownRefresh() {
    this.init()
  },
  init() {
    var that = this
    var openid = wx.getStorageSync('openid')
    wx.request({
      url: config.baseUrl + "/GetReservation?openid=" + openid + "&lang=" + wx.getStorageSync('lang'),
      method: "GET",
      header: {
        "content-type": "application/json"
      },
      success(e) {
        console.log(e.data)
        that.setData({
          goodsList: e.data
        })
      },
      fail(e) {
        that.setData({
          goodsList: null
        })
      }
    })
  },
  goodListClickHandle(e) {
    // console.log(e.currentTarget.dataset.id)
    const index = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `Details?orderid=${index}`,
    })
  },
})
